package cn.tedu.sp04.feign;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.util.JsonResult;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class ItemClientFB implements ItemClient {
    @Override
    public JsonResult<List<Item>> getItems(String orderId) {
        //模拟返回缓存数据
        if (Math.random() < 0.5) {
            return JsonResult.ok().data(  //如果有缓存，返回缓存数据

                    Arrays.asList(new Item[]{
                            new Item(1, "缓存aaa", 2),
                            new Item(2, "缓存bbb", 1),
                            new Item(3, "缓存ccc", 3),
                            new Item(4, "缓存ddd", 1),
                            new Item(5, "缓存eee", 5)
                    })

            );
        }
        return JsonResult.err().msg("调用商品失败");
    }

    @Override
    public JsonResult decreaseNumber(List<Item> items) {
        return JsonResult.err().msg("无法修改商品");
    }
}
